package com.datastructure.test.numberofone;

public class NumberOfOne {

    public static void main(String[] args) {
        System.out.println(new NumberOfOne().countDigitOne(13));
        //System.out.println('1');
    }

    public int countDigitOne(int n) {
        int sum = 0;
        if(n<0){
            return sum;
        }
        String data = String.valueOf(n);
        byte[] bytes = data.getBytes();
        for (int i = 0; i < bytes.length; i++) {
            if(bytes[i]==49){
                sum++;
            }
        }
        return sum+countDigitOne(n-1);
    }
}
